<?php
require '../../packages/connect_database.php';
mysql_select_db("auction");
$auction = "";
$query = mysql_query("SELECT phone FROM auction");
$result = mysql_fetch_row($query);
if($result[0] != $_COOKIE["phone"]) {
	echo $auction;
	exit();
}
$query_table = mysql_list_tables("auction");
$i = 0;
$creator = false;
while($i < mysql_num_rows($query_table)) {
	$table[$i] = mysql_tablename($query_table, $i);
	if($table[$i] != "auction" && $table[$i] != "setup") {
		$query = mysql_query("SELECT * FROM " . $table[$i] . " WHERE creator = 1");
		if(mysql_num_rows($query) > 0)
			$creator = true;
		else {
			$creator = false;
			break;
		}
	}
	$i++;
}
if(!$creator) {
	$auction = $i;
	mysql_query("INSERT INTO room" . $i . " VALUES(0,'" . $_COOKIE["name"] . "','" . $_COOKIE["phone"] . "',true)") or die(mysql_error());
}
echo $auction;
